package pers.lan.th.java.lock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author <p><a href="mailto:1728209643@qq.com">XiaoSan</a>
 * @date 2019/11/29 3:42 PM
 */
public class ReetrantLockTest {

    private int n;

    ReentrantLock lock = new ReentrantLock();

    private void add(int i) {
        lock.lock();
        n += i;
        System.out.println(Thread.currentThread().getId() + " ==> " + n);
        lock.unlock();
    }

    public static void main(String[] args) {
        ReetrantLockTest lockTest = new ReetrantLockTest();
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                for (int i1 = 0; i1 < 100000; i1++) {
                    lockTest.add(10);
                }
            }).start();
        }
    }
}
